<?php
namespace app\common\model\factory;

use think\Model;

class UserFactory extends Model
{
    protected $table = 'user_factory';
    protected $pk = 'id';

    /**
     * 通过 user_id 获取 factory_id
     */
    public static function getFactoryIdByUserId($user_id)
    {
        return self::where('user_id', $user_id)->value('factory_id');
    }

    /**
     * 通过 factory_id 获取所有 user_id
     */
    public static function getUserIdsByFactoryId($factory_id)
    {
        return self::where('factory_id', $factory_id)->column('user_id');
    }

    /**
     * 添加 user-factory 关联
     */
    public static function addUserFactory($user_id, $factory_id)
    {
        return self::create([
            'user_id' => $user_id,
            'factory_id' => $factory_id,
        ]);
    }

    /**
     * 删除 user-factory 关联
     */
    public static function delUserFactory($user_id)
    {
        return self::where('user_id', $user_id)->delete();
    }
} 